package common.server.quartz;

import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @author Administrator
 * @version [版本号, 2017/11/29 0029]
 * @see [相关类/方法]
 * @since [产品/模块版本]
 */
public class QuartzJobFactory implements org.quartz.Job{

    /**
     * 日志
     */
    protected static final Logger logger = LoggerFactory.getLogger(QuartzJobFactory.class);

    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        JobInfo info = (JobInfo)jobExecutionContext.getMergedJobDataMap().get("JobInfo");
        long starttime = System.currentTimeMillis();
        logger.info("[ST:{}] Start Job:{}", starttime, info);
        try{
            if(info != null && info.getJob() != null){
                //执行job
                info.getJob().execute(info);
            }
            else{
                logger.warn("Job execute fail! JobInfo or Job is null!");
            }
        }catch (Exception e){
            logger.error("QuartzJob Error:",e);
        }
        logger.info("[CT:{}] End Job:{}" ,System.currentTimeMillis()-starttime, info);
    }
}
